package com.lh.eemsserver.Mapper;

import com.lh.eemsserver.po.Procedure;
import com.lh.eemsserver.po.Report;
import com.lh.eemsserver.po.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Mapper
public interface SpecialistMapper {

    @Select("select * from eemsdb.reporter,eemsdb.report,eemsdb.eventtype,eemsdb.event,eemsdb.legalperson,eemsdb.riskenterprise where legalperson.legalpersonphone=riskEnterprise.legalpersonphone and riskEnterprise.enterpriseID=report.enterpriseID and report.eventID=event.eventID and event.eventType=eventtype.eventType and report.reporterPhone = reporter.reporterPhone and reportState IN ('专家人员审批中')")
    public List<Report> listAllReport();
    //理解po层的含义，该层是解决业务中的返回值类型的，应根据业务需求获取返回值并在po层建立相应的类，而不是数据库有什么我建什么

    @Select("select * from eemsdb.reporter,eemsdb.report,eemsdb.eventtype,eemsdb.event,eemsdb.legalperson,eemsdb.riskenterprise where legalperson.legalpersonphone=riskEnterprise.legalpersonphone and riskEnterprise.enterpriseID=report.enterpriseID and report.eventID=event.eventID and event.eventType=eventtype.eventType and report.reporterPhone = reporter.reporterPhone and reportState not IN ('专家人员审批中','指挥人员审批中','待审批')")
    public List<Report> listAllReportExceptApprovalPending();
    @Select("select * from eemsdb.`procedure` where eventType=#{eventType}")
    public List<Procedure> getProcedure(Report report);
    //通过流程类型获取流程信息

    @Select("select count(*) as procedureNum from eemsdb.`procedure` where eventType=#{eventType}")
    public int getProcedureNum(Report report);


    public int renewUpdaterInfo(Report report);
    //专家点击通过或者驳回按钮后 更新该接报的lastUpdateTime，lastUpdateUser，reportState，remark等信息

    public User getUserName(User user);
    //既适用于登录又适用于登陆成功后界面右上角信息展示

    @Select("select * from eemsdb.reporter,eemsdb.report,eemsdb.eventtype,eemsdb.event,eemsdb.legalperson,eemsdb.riskenterprise where legalperson.legalpersonphone=riskEnterprise.legalpersonphone and riskEnterprise.enterpriseID=report.enterpriseID and report.eventID=event.eventID and event.eventType=eventtype.eventType and report.reporterPhone = reporter.reporterPhone and  reportID = #{reportID}")
    public Report getReportById(Report report);


    @Update("update eemsdb.report set lastUpdater = #{lastUpdater} , reportState=#{reportState} , lastUpdateTime=#{lastUpdateTime} where report.reportID=#{reportID}")
    public int setUpdaterInfo(Report report);

    @Update("update eemsdb.report set reportState=#{reportState} where report.reportID=#{reportID}")
    public int renewreportState(Report report);
}
